﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Model;
using Microsoft.Practices.EnterpriseLibrary.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data;

namespace DAL
{
   public class AddInterviewDAL
    {
       /// <summary>
        /// 链接数据库
        /// </summary>
        Database db = DatabaseFactory.CreateDatabase("constring");

       //public int AddInterview(Interview iw)
       // {
       //     string sql = string.Format("insert into Interview(position_id,interview_data,interview_tapes,interview_image,interview_attached,interview_del,interview_integrity,Firm_Id,User_id,Rated_Id) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}')",iw);
       //     int a = db.ExecuteNonQuery(CommandType.Text,"insert into ");
       // }


       /// <summary>
       /// 职位下拉框绑定
       /// </summary>
       /// <returns></returns>
        public List<Position> DropPosition()
        {
            DataSet ds = db.ExecuteDataSet(CommandType.Text, "select position_id,position_name  from Position");
            List<Position> li = new List<Position>();
            var DRows = ds.Tables[0].Rows;
            foreach (DataRow dr in DRows)
            {
                Position pos = new Position();
                pos.position_id = Convert.ToInt32(dr["position_id"]);
                pos.position_name = dr["position_name"].ToString();
                li.Add(pos);
            }
            return li;
        }


       /// <summary>
       /// 显示面试经验详细信息
       /// </summary>
       /// <param name="id"></param>
       /// <returns></returns>
        public Interview ShowInterview(int id)
        {
            DataSet ds = db.ExecuteDataSet(CommandType.Text, "select Login_Nickname,Login_Name,interview_id,position_name,Firm_Name,interview_data,interview_tapes,interview_image,interview_attached from Interview left join Firm on Interview.Firm_Id=Firm.Firm_Id left join Users on Interview.User_id=Users.Login_Id left join position on Interview.position_id=position.position_id where Interview.interview_id=" + id);

            DataRow dr=ds.Tables[0].Rows[0];
            Interview ii = new Interview();
            ii.Login_Nickname = dr["Login_Nickname"].ToString();
            ii.interview_id = Convert.ToInt32(dr["interview_id"]);
            ii.Login_Name = dr["Login_Name"].ToString();
            ii.position_name = dr["position_name"].ToString();
            ii.Firm_Name = dr["Firm_Name"].ToString();
            ii.interview_data = dr["interview_data"].ToString();
            ii.interview_tapes = dr["interview_tapes"].ToString();
            ii.interview_image = dr["interview_image"].ToString();
            ii.interview_attached = dr["interview_attached"].ToString();

            return ii;
        }
    }
}
